package com.vms.data;

import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

public class CheckerLocation implements LocationListener {
	private static CheckerLocation instance;
	private double latitude;
	private double longitude;
	private LocationManager mLocationManager;

	private CheckerLocation(LocationManager aLocationManager) {
		this.mLocationManager = aLocationManager;
		mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000L, 500.0f, this);
		
		Criteria criteria = new Criteria();
		String bestProvider = mLocationManager.getBestProvider(criteria, false);
		Location location = mLocationManager.getLastKnownLocation(bestProvider);
		if(location != null){
			this.latitude = location.getLatitude();
			this.longitude = location.getLongitude();
		}
	}

	public void onLocationChanged(Location location) {
		this.latitude = location.getLatitude();
		this.longitude = location.getLongitude();
	}

	public void onProviderDisabled(String provider) {
	}

	public void onProviderEnabled(String provider) {
	}

	public void onStatusChanged(String provider, int status, Bundle extras) {

	}

	public static CheckerLocation getInstance(LocationManager aLocationManager) {
		if (aLocationManager != null) {
			instance = new CheckerLocation(aLocationManager);
		}
		return instance;
	}

	public double getLatitude() {
		return latitude;
	}

	public double getLongitude() {
		return longitude;
	}
}